package com.emm.yixun.mobile.adapter;

import java.util.ArrayList;

import xf.tools.RoundImageView;

import com.emm.yixun.mobile.model.ArmorModel;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.emm.yixun.mobile.R;

public class ArmoryAdapter extends BaseAdapter {

	Context context;

	ArrayList<ArmorModel> list;

	public ArmoryAdapter(Context context, ArrayList<ArmorModel> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? null : list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoudlerArmory v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.armory_adapter_item, null);
			v = new ViewHoudlerArmory();
			v.name1 = (TextView) convertView.findViewById(R.id.name1);
			v.name2 = (TextView) convertView.findViewById(R.id.name2);
			v.name3 = (TextView) convertView.findViewById(R.id.name3);
			v.rdimageview1 = (RoundImageView) convertView.findViewById(R.id.rdimageview1);
			v.rdimageview2 = (RoundImageView) convertView.findViewById(R.id.rdimageview2);
			v.rdimageview3 = (RoundImageView) convertView.findViewById(R.id.rdimageview3);
			v.icon_image = (ImageView) convertView.findViewById(R.id.icon_image);
			v.title_name = (TextView) convertView.findViewById(R.id.title_name);
			convertView.setTag(v);
		} else {
			v = (ViewHoudlerArmory) convertView.getTag();
		}
		if (position == 0) {
			v.icon_image.setImageResource(R.drawable.icon_phb_rc);
		} else if (position == 1) {
			v.icon_image.setImageResource(R.drawable.icon_phb_rg);
		} else {
			v.icon_image.setImageResource(R.drawable.icon_phb_qy);
		}

		v.name1.setText(list.get(position).getMessag().get(0).getName());
		v.name2.setText(list.get(position).getMessag().get(1).getName());
		v.name3.setText(list.get(position).getMessag().get(2).getName());
		v.title_name.setText(list.get(position).getTitle());

		return convertView;
	}

	public static class ViewHoudlerArmory {
		TextView name3, name2, name1, title_name;
		RoundImageView rdimageview3, rdimageview2, rdimageview1;
		ImageView icon_image;
	}

}
